package pers.tetris;

import java.util.Arrays;

/**
 * 固定化的形状
 * 原有的Shape类每次旋转需要计算一次，本类提供一个预先设置好的形状序列，每次旋转时变为下一个形状
 */
public class FixedShape extends Shape implements Cloneable{
    final int[][][] shapes;
    final static int[][] EMPTY_SHAPE = new int[0][];
    String name;
    int mode = 0;

    public FixedShape(int[][]... initShapes) {
        super(EMPTY_SHAPE);
        shapes = initShapes;
    }

    @Override
    public void rotate() {
        mode++;
    }

    /**
     * 转回去
     */
    public void rotateBack(){
        mode--;
    }

    @Override
    public int[][] getShape() {
        return shapes[mode%shapes.length];
    }

    @Override
    public String toString() {
        return "FixedShape{" +
                "shapes=" + Arrays.deepToString(shapes) +
                ", mode=" + mode +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    @Override
    public FixedShape clone() {
        return (FixedShape) super.clone();
    }
}
